<?php

/**
 * GotStudentActivites insertion and edition handler
 * @package ModuleGestionUniversitaire
 * @version 1.0b
 */

session_start();

// Configuration file
include 'configuration.php';
// Functions
include 'inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	header('Location: index.php');
	exit();
endif;

// Include all objects
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

// ---------- START: HEAD
include $configuration['webroot'].'inc/head.php';
// ---------- END: HEAD

// ---------- START: MENU
include $configuration['webroot'].'inc/menu.php';
// ---------- END: MENU

// ---------- START: BODY

if (isset($_GET['operation'])) :

	$gotstudentactivity = new GotStudentActivity();
	$dateFrom = $dateTo = date('d/m/Y');
	
	// In case we are in an insert state
	if ($_GET['operation'] == 'add'):
		$company = new Company();
		$contact = new Contact();
		$remuneration = new Remuneration();
		$remuneration->amount = 0;
		$remuneration->type = 'MONTH';
		if (isset($_GET['sid'])) $company->Get($_GET['sid']);
		if (isset($_GET['cid'])) $contact->Get($_GET['cid']);
		$gotstudentactivity->SetCompany($company);
		$gotstudentactivity->SetContact($contact);
		$gotstudentactivity->SetRemuneration($remuneration);
	
	// In case we are in an update state
	elseif (($_GET['operation'] == 'edit') && isset($_GET['id'])):
		$gotstudentactivity->Get($_GET['id']);
		$company = $gotstudentactivity->GetCompany();
		$contact = $gotstudentactivity->GetContact();
		$remuneration = $gotstudentactivity->GetRemuneration();
		if (strlen($gotstudentactivity->from) > 0):
			$dateFrom = explode('-', $gotstudentactivity->from);
			$dateFrom = $dateFrom[2].'/'.$dateFrom[1].'/'.$dateFrom[0];
		endif;
		if (strlen($gotstudentactivity->to) > 0):
			$dateTo = explode('-', $gotstudentactivity->to);
			$dateTo = $dateTo[2].'/'.$dateTo[1].'/'.$dateTo[0];
		endif;
	endif;

	include 'forms/studentactivity.php';

endif;
// ---------- END: BODY

// ---------- START: FOOT
include $configuration['webroot'].'inc/foot.php';
// ---------- END: FOOT

// ---------- JAVASCRIPTS AND END
include $configuration['webroot'].'inc/js.php'; ?>
<script type="text/javascript" src="js/studentactivities.js"></script>

</body>
</html>